package com.dc.project.sales.controller;

import com.dc.common.validated.InsertGroup;
import com.dc.common.validated.QueryGroup;
import com.dc.common.validated.UpdateGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.sales.dto.SalOrderDetailDto;
import com.dc.project.sales.entity.SalOrderDetail;
import com.dc.project.sales.service.SalOrderDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 销售订单明细表(SalOrderDetail)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-12 16:37:13
 */
@RestController
@RequestMapping("salOrderDetail")
@Api(tags = "销售订单明细表")
public class SalOrderDetailController {
    /**
     * 服务对象
     */
    @Autowired
    private SalOrderDetailService salOrderDetailService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @RequiresPermissions("system:salOrderDetail:query")
    public ResultVo get(@PathVariable Serializable id) {
        return this.salOrderDetailService.queryById(id);
    }

    /**
     * 查询销售订单明细表列表
     *
     * @param dto
     * @return
     */
    @GetMapping("list")
    @ApiOperation("查询销售订单明细表列表")
    @RequiresPermissions(value = {"system:salOrderDetail:query", "sales:salOrder:query"}, logical = Logical.OR)
    public ResultVo list(@Validated(QueryGroup.class) SalOrderDetailDto dto) {
        return this.salOrderDetailService.queryByList(dto);
    }

    /**
     * 新增销售订单明细表
     *
     * @param salOrderDetail
     * @return
     */
    @PostMapping
    @ApiOperation("新增销售订单明细表")
    @RequiresPermissions("system:salOrderDetail:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody SalOrderDetail salOrderDetail) {
        return this.salOrderDetailService.add(salOrderDetail);
    }

    /**
     * 编辑销售订单明细表
     *
     * @param salOrderDetail
     * @return
     */
    @PutMapping
    @ApiOperation("编辑销售订单明细表")
    @RequiresPermissions("system:salOrderDetail:edit")
    public ResultVo edit(@Validated(value = {UpdateGroup.class}) @RequestBody SalOrderDetail salOrderDetail) {
        return this.salOrderDetailService.edit(salOrderDetail);
    }

    /**
     * 根据主键删除销售订单明细表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除销售订单明细表")
    @RequiresPermissions("system:salOrderDetail:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.salOrderDetailService.delete(id);
    }

}